// 一维 28ms
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 30, M = 30010;

int v[N], p[N];
int dp[M];
int n, m;

int main()
{
    cin >> m >> n;
    for (int i = 1; i <= n; i ++ )
        cin >> v[i] >> p[i];
    
    for (int i = 1; i <= n; i ++ )
        for (int j = m; j >= v[i]; j -- )
        {
            dp[j] = max(dp[j], dp[j - v[i]] + v[i] * p[i]);
        }
        
    cout << dp[m] << endl;
    return 0;
}
// 二维 41ms
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 30, M = 30010;

int v[N], p[N];
int dp[N][M];
int n, m;

int main()
{
    cin >> m >> n;
    for (int i = 1; i <= n; i ++ )
        cin >> v[i] >> p[i];
    
    for (int i = 1; i <= n; i ++ )
        for (int j = 0; j <= m; j ++ )
        {
            dp[i][j] = dp[i - 1][j];
            if (j >= v[i]) dp[i][j] = max(dp[i - 1][j - v[i]] + v[i] * p[i], dp[i][j]);
        }
    
    cout << dp[n][m];
    return 0;
}
